07 Upload da foto

Próxima Atividade
  • Sugerir melhoria
Play
Current Time 0:00
/
Duration Time 0:00
Remaining Time -0:00
Stream TypeLIVE
Loaded: 0%
Progress: 0%
0:00
Fullscreen
00:00
Mute
Playback Rate
  • 2x
  • 1.5x
  • 1.2x
  • 1x
  • 0.8x
  • 0.7x
1x
Subtitles
  • subtitles off
Captions
  • captions off
Chapters
  • Chapters
HD
Desculpe-nos pelo transtorno, mas este video não pode ser carregado, tente novamente.

Transcrição

import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';

import { Photo } from "./photo";

const API = 'http://localhost:3000';

@Injectable({ providedIn: 'root' })
export class PhotoService {

    constructor(private http: HttpClient) {}

    listFromUser(userName: string) {
        return this.http
            .get<Photo[]>(API + '/' + userName + '/photos');       
    }

    listFromUserPaginated(userName: string, page: number) {
        const params = new HttpParams()
            .append('page', page.toString());

        return this.http
            .get<Photo[]>(API + '/' + userName + '/photos', { params });       
    }    

    upload(formData: FormData) {
        return this.http.post(
            API + '/photos/upload', formData
        );
    }    
}
import { Component, OnInit } from "@angular/core";

import { AuthService } from "../../core/auth/auth.service";
import { FormGroup, FormBuilder } from "@angular/forms";
import { Validators } from "@angular/forms";

@Component({
    selector: 'ap-photo-form',
    templateUrl: './photo-form.component.html',
})
export class PhotoFormComponent implements OnInit {

    photoForm: FormGroup;

    constructor(private formBuilder: FormBuilder) { }

    ngOnInit(): void { 

        this.photoForm = this.formBuilder.group({
            file: ['', Validators.required],
            description: ['', Validators.maxLength(300)],
            allowComments: [true]
        });
    }

    upload() {
        console.log('chamou upload');
    }
}
<div class="container" (submit)="upload()">
  <form [formGroup]="photoForm" class="row">
Tirar dúvida Próxima Atividade
ícone Angular parte 3: upload, build e novos componentes

Angular parte 3: upload, build e novos componentes

100%
Aula01 de 08

Upload de fotos

Atividades 7 de 12

  • 01 Projeto da aula anterior
  • 02 Este curso é uma continuação
  • 03 Rodapé 10min
  • 04 O formulário upload de fotos 06min
  • 05 Validando o formulário 07min
  • 06 Obtendo os dados do formulário 07min
  • 07 Upload da foto 07min
  • 08 Sobre o upload
  • 09 Arquivo selecionado
  • 10 FormData
  • 11 Adequando a exibição das fotos 07min
  • 12 Consolidando seu conhecimento

Aulas

Outros Links

Fórum Trocar Curso
Gravatar de Marcos Katsumi Kay

Marcos Katsumi Kay 34.4k xp

Logo da Alura